package cn.com.cpic.insurance.rulecheck.core;

import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * 一个简单实现的可修改集合
 * 
 * @author 代波
 * @since 2011-8-13
 * @param <T> 集合中元素的类型
 */
public final class SimpleModifiableSet<T> implements ModifiableSet<T> {
	private static final long serialVersionUID = 7978137061176312967L;

	private final Set<T> set;

	public SimpleModifiableSet(Set<T> set) {
		this.set = Collections.synchronizedSet(set == null ? new HashSet<T>() : set);
	}

	public SimpleModifiableSet(T... set) {
		this((Set<T>) null);
		for (T t : set) {
			add(t);
		}
	}

	public boolean contains(T c) {
		return set.contains(c);
	}

	public boolean add(T c) {
		return set.add(c);
	}

	public boolean remove(T c) {
		return set.remove(c);
	}

	public Iterator<T> iterator() {
		return new HashSet<T>(set).iterator();
	}

	public int size() {
		return set.size();
	}

	public boolean isEmpty() {
		return set.isEmpty();
	}
}
